package com.wisemoresystem.seal.action.mac.over;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_mac;
import com.wisemoresystem.seal.model.t_mac_move_log;
import com.wisemoresystem.seal.service.MacMoveLogService;
import com.wisemoresystem.seal.service.MacService;

/**
 * 上缴 接收
 * 
 * @author 冯晓东
 *
 */
@Controller("macOverRecv")
@Scope("prototype")
@RequestMapping("/ix/mac/over/recv")
public class MacOverRecvAction extends ProjBaseAction {

	@Autowired
	private MacService macService;
	@Autowired
	private MacMoveLogService macLogService;

	/**
	 * 上缴接收列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> macList = macService.selectOverRecvingList(
				srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/mac/over/recv/list");
		mv.addObject("macList", macList);
		mv.addObject("srh_name", srh_name);
		return mv;
	}

	@RequestMapping("/recv_form")
	public ModelAndView recv_form(String mac_id) {

		t_mac mac = oc.findObjById(mac_id, t_mac.class);
		t_mac_move_log log = macLogService.findOverVerifyedLog(mac.get_id());
		t_bank bank = oc.findObjById(log.getBank_id(), t_bank.class);
		t_bank destBank = oc.findObjById(log.getBank_id_dest(), t_bank.class);

		ModelAndView mv = new ModelAndView("/jsp/mac/over/recv/recv_form");
		mv.addObject("mac", mac);
		mv.addObject("log", log);
		mv.addObject("bank", bank);
		mv.addObject("destBank", destBank);
		return mv;
	}

	/**
	 * 上缴接收
	 * 
	 * @param mac_id
	 *            印控仪id
	 * @param note
	 *            上缴接收备注
	 * @return
	 */
	@RequestMapping("/recv")
	public ModelAndView recv(String mac_id, String note) {

		boolean isStart = macLogService.over_recv(mac_id, note);
		if (isStart) {
			this.setTipMsg("接收成功!", Tip.Type.success);
			logT.logH("印控仪接收", t_mac.class, mac_id);
		} else {
			this.setTipMsg("接受失败!该设备状态有误!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}
